﻿using Core;
using FairyGUI;
using UnityEngine;

public class TouchWidget:FGUIWidget<GObject>
{
    Vector2 touchPos;
    protected override void OnInitialize(params object[] args)
    {
        m_root.onTouchBegin.Add(OnTouchBegion);
        m_root.onTouchMove.Add(OnTouchMove);
    }

    private void OnTouchBegion(EventContext context)
    {
        context.CaptureTouch();
        touchPos = context.inputEvent.position;
    }

    private void OnTouchMove(EventContext context)
    {
        var delta = context.inputEvent.position - touchPos;
        var cameraComponent = Player.Instance.GetParent<Unit>().GetComponent<CameraComponent>();
        // 设置触摸移动的方向
        cameraComponent.SetDelta(delta.normalized);
        touchPos = context.inputEvent.position;
    }
}